custom paper dialog: Use headerbar
authorWilliam Jon McCann <william.jon.mccann@gmail.com>
Sun, 8 Dec 2013 14:58:00 +0000 (15:58 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 17 Jan 2014 22:52:08 +0000 (17:52 -0500)
Make the custom paper dialog use a headerbar when desired.

https://bugzilla.gnome.org/show_bug.cgi?id=720059

gtk/gtkcustompaperunixdialog.c

index 09fb139dad2e04fd3485323e01648f01683ff906..ec2c11725a29c47b915ea991765d3122f006b1ec 100644 (file)
@@ -37,6 +37,7 @@
 #include "gtkcustompaperunixdialog.h"
 #include "gtkprintbackend.h"
 #include "gtkprintutils.h"
+#include "gtkdialogprivate.h"
 
 #define LEGACY_CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
 #define CUSTOM_PAPER_FILENAME "custom-papers"
@@ -89,6 +90,9 @@ enum {
 G_DEFINE_TYPE_WITH_PRIVATE (GtkCustomPaperUnixDialog, gtk_custom_paper_unix_dialog, GTK_TYPE_DIALOG)
 
 
+static GObject *gtk_custom_paper_unix_dialog_constructor (GType            type, 
+                                                          guint            n_params,
+                                                          GObjectConstructParam *params);
 static void gtk_custom_paper_unix_dialog_finalize  (GObject                *object);
 static void populate_dialog                        (GtkCustomPaperUnixDialog *dialog);
 static void printer_added_cb                       (GtkPrintBackend        *backend,
@@ -269,6 +273,7 @@ _gtk_print_save_custom_papers (GtkListStore *store)
 static void
 gtk_custom_paper_unix_dialog_class_init (GtkCustomPaperUnixDialogClass *class)
 {
+  G_OBJECT_CLASS (class)->constructor = gtk_custom_paper_unix_dialog_constructor;
   G_OBJECT_CLASS (class)->finalize = gtk_custom_paper_unix_dialog_finalize;
 }
 
@@ -291,6 +296,8 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
   dialog->priv = gtk_custom_paper_unix_dialog_get_instance_private (dialog);
   priv = dialog->priv;
 
+  gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
+
   priv->print_backends = NULL;
 
   priv->request_details_printer = NULL;
@@ -307,13 +314,29 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
 
   populate_dialog (dialog);
 
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-                          _("_Close"), GTK_RESPONSE_CLOSE,
-                          NULL);
+  g_signal_connect (dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), NULL);
+}
 
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
+static GObject *
+gtk_custom_paper_unix_dialog_constructor (GType            type, 
+                                          guint            n_params,
+                                          GObjectConstructParam *params)
+{
+  GObject *object;
+  gboolean use_header;
 
-  g_signal_connect (dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), NULL);
+  object = G_OBJECT_CLASS (gtk_custom_paper_unix_dialog_parent_class)->constructor (type, n_params, params);
+
+  g_object_get (object, "use-header-bar", &use_header, NULL);
+  if (!use_header)
+    {
+      gtk_dialog_add_buttons (GTK_DIALOG (object),
+                              _("_Close"), GTK_RESPONSE_CLOSE,
+                              NULL);
+      gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CLOSE);
+    }
+
+  return object;
 }
 
 static void
@@ -381,7 +404,7 @@ gtk_custom_paper_unix_dialog_finalize (GObject *object)
  */
 GtkWidget *
 _gtk_custom_paper_unix_dialog_new (GtkWindow   *parent,
-                                 const gchar *title)
+                                   const gchar *title)
 {
   GtkWidget *result;
 
@@ -1015,10 +1038,9 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
   GtkStyleContext *context;
 
   content_area = gtk_dialog_get_content_area (cpu_dialog);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS 
   action_area = gtk_dialog_get_action_area (cpu_dialog);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
+G_GNUC_END_IGNORE_DEPRECATIONS 
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
@@ -1219,6 +1241,5 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       add_custom_paper (dialog);
     }
 
-  gtk_window_present (GTK_WINDOW (dialog));
   load_print_backends (dialog);
 }